package com.kun.index.controller;


import com.kun.common.ResultDto;
import com.kun.index.controller.dto.AddBlogLabelDto;
import com.kun.index.entity.BlogLabel;
import com.kun.index.entity.LikeUserBlog;
import com.kun.index.service.impl.LikeUserBlogServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 点赞表，用户和博客 前端控制器
 * </p>
 *
 * @author kunkun
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/index/like-user-blog")
public class LikeUserBlogController {

    @Autowired
    private LikeUserBlogServiceImpl likeUserBlogService;

    @PostMapping("/addLike")
    @ApiOperation("点赞")
    public ResultDto addLike(@RequestBody LikeUserBlog likeUserBlog) {

        Integer num = likeUserBlogService.addLike(likeUserBlog);
        if (num!=null){
            return ResultDto.success("点赞成功");
        }else{
            return ResultDto.fail("点赞失败");
        }
    }

    @PostMapping("/deleteLike")
    @ApiOperation("取消点赞")
    public ResultDto deleteLike(@RequestBody LikeUserBlog likeUserBlog) {

        Integer num = likeUserBlogService.deleteLike(likeUserBlog);
        if (num!=null){
            return ResultDto.success("取消点赞成功");
        }else{
            return ResultDto.fail("取消点赞失败");
        }
    }

    @PostMapping("/checkLikeStatus")
    @ApiOperation("查询点赞状态")
    public ResultDto checkLikeStatus(@RequestBody LikeUserBlog likeUserBlog) {

        Integer num = likeUserBlogService.checkLikeStatus(likeUserBlog);
        if (num!=null && num>0){
            return ResultDto.success("已经点赞");
        }else{
            return ResultDto.fail("未点赞");
        }
    }



}

